package pl.smath.operation.basic;

import junit.framework.TestCase;
import pl.smath.expression.ProductTerm;
import pl.smath.expression.SymbolTerm;
import pl.smath.expression.Term;
import pl.smath.operation.BasicOp;
import pl.smath.parser.ExpressionParser;


public class MultiplyTestCase extends TestCase {

	/** 
	 * Test data. Format:
	 * input => expected output 
	 */
	private static final String[][] testData = {
		{"2+3","2+3"},
		{"2*3","6"},
		{"2*3.2","6.4"},
		{"3*4/2","12/2"},
		{"4/2*3","12/2"},
		{"2*x","2*x"},
		{"x*x","x^2"},
		{"x^2*x","x^3"},
		{"x*x^2","x^3"},
		{"x/x*x*x","x^3/x"},
		{"x^2*x^3","x^5"}
	};
	
	
	public void testData() {
		ExpressionParser parser = new ExpressionParser();
		Term	input;
		Term	output;
		
		for(int i = 0; i < testData.length; i++){
//System.out.println(testData[i][0]);		
			input = parser.parseText( testData[i][0] );
			if(input instanceof ProductTerm){
				output = BasicOp.simplify( input );
			}
			else{
				output = input;
			}
			
			assertEquals("Input: " + testData[i][0], testData[i][1], output.toString());
		}
	}

	
	public void testForce1() {
		MultiplyOp op = new MultiplyOp();
		SymbolTerm t1 = new SymbolTerm("x");
		SymbolTerm t2 = new SymbolTerm("y");
		
		t2.setNegative(true);
		
		Term term = op.forceMultiply(t1, t2);
		
		assertEquals("-x*y", term.toString());
	}
}
